const Koa = require('koa')
const router = require('koa-router')()
const bodyParser = require('koa-bodyparser')
const static = require('koa-static')
const path = require('path')
const studentRouter = require('./routes/student/student')
const articleRouter = require('./routes/article')
const organizationRouter = require('./routes/organization/organization')

const app = new Koa()

app.use(bodyParser())
app.use(static(path.join(__dirname, 'views')))

app.use(async (ctx, next) => {
    console.log('应用中间件')
    ctx.cookies.set('authorization','e4d5fg67f7g7h8g7ffhrje')
    next()
})

router.get('/', async (ctx, next) => {
    await  ctx.render('index');
})

router.use('/student',studentRouter)
router.use('/article', articleRouter)
router.use('/organization', organizationRouter)

app.use(router.routes())
    .use(router.allowedMethods());

app.listen(3000)
